<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>Layui</title>
    <link rel="stylesheet" type="text/css" href="../static/layui/css/layui.css">
    <script type="text/javascript" src="../static/js/jquery-3.3.1.min.js"></script>
    <!-- 注意：如果你直接复制所有代码到本地，上述css路径需要改成你本地的 -->
    <style>
        /*鼠标放上小手标志*/
        font {
            cursor: pointer;
        }
    </style>
</head>
<body>
<div class="demoTable" style="position: absolute;z-index: 1000 ;margin-top: 5px;">
    <form>
        <select id="domoin" name="domoin" style="width: 180px;height: 38px;border-color: #efefef;"></select>

        <select id="departments" name="departments" style="width: 180px;height: 38px;border-color: #efefef;"></select>

        <select id="rank" name="rank" style="width: 180px;height: 38px;border-color: #efefef;"></select>


        <div class="layui-inline">
            <input class="layui-input" name="demoReload" id="demoReload" autocomplete="off" placeholder="请输入关键词">
        </div>
        <button class="layui-btn" data-type="reload" id="reload">查询</button>
        <div class="layui-input-inline">
            <input type="reset" class="layui-input"
                   style="width: 60px;height: 38px;text-align: center;background-color:#16c4ff;color: white ">
        </div>
    </form>
</div>
<script type="text/html" id="zizeng">
    {{d.LAY_TABLE_INDEX+1}}
</script>
<table class="layui-hide" id="test" lay-filter="test"></table>


<script type="text/html" id="toolbarDemo">
    <div class="layui-btn-container">
        <a lay-event="addlevel">
            <button class="layui-btn layui-btn-sm" onclick="addle()" style="float: right;margin-right: -80px; margin-top: 10px;">
                添加政策
            </button>
        </a>
        <button class="layui-btn layui-btn-sm" id="deleteUserByIds" style="float: right;margin-right: 20px; margin-top: 10px;">批量删除</button>
    </div>
</script>
<!-- 操作指令 -->
<script type="text/html" id="barDemo">
    <a lay-event="edit">
        <font color="#0000FF">编辑</font>
    </a>
    <a>|</a>
    <a lay-event="stop">
        <font color="#0000FF">停用</font>
    </a>
    <a>|</a>
    <a lay-event="del">
        <font color="red">删除</font>
    </a>
</script>


<script src="../static/layui/layui.js"></script>
<!-- 注意：如果你直接复制所有代码到本地，上述 JS 路径需要改成你本地的 -->

<script>
    layui.use('table', function () {
        var table = layui.table;
        table.render({
            elem: '#test',
            url: 'polman',
            toolbar: '#toolbarDemo',
            defaultToolbar: ['exports'],
            title: '政策管理表',
            id: 'testReload',
            cols: [
                [{
                    type: 'checkbox'
                    // fixed: 'left'
                }, {
                    field: 'zizeng',
                    width: 110,
                    title: '序号',
                    templet: '#zizeng',
                    hide: true
                }, {
                    field: 'circular_id',
                    title: 'ID',
                    hide: true
                }, {
                    field: 'circular_title',
                    title: '标题',
                    // width: 1175,
                    align: 'center'
                },{
                    field: 'domoin_name',
                    title: '领域',
                    // width: 1175,
                    align: 'center'
                },{
                    field: 'department_name',
                    title: '部门',
                    // width: 1175,
                    align: 'center'
                },{
                    field: 'rank_name',
                    title: '级别',
                    // width: 1175,
                    align: 'center'
                },{
                    field: 'circular_date',
                    title: '日期',
                    // width: 1175,
                    align: 'center'
                },{
                    field: 'project_name',
                    title: '包含项目',
                    // width: 1175,
                    align: 'center'
                }, {
                    fixed: 'right',
                    title: '操作',
                    toolbar: '#barDemo',
                    width: 450
                }]
            ],
            page: { //支持传入 laypage 组件的所有参数（某些参数除外，如：jump/elem） - 详见文档
                layout: ['count', 'prev', 'page', 'next', 'limit', 'skip']//自定义分页布局
                , first: false //不显示首页
                , last: false //不显示尾页
            },
            height: 550
        });


// 模糊查询 搜索
        var $ = layui.$, active = {
            reload: function () {
                var demoReload = $('#demoReload').val();
                var domoin = $('#domoin').val();
                var departments = $('#departments').val();
                var rank = $('#rank').val();

                //执行重载
                table.reload('testReload', {
                    page: {
                        curr: 1 //重新从第 1 页开始
                    },
                    where: {
                        demoReload: demoReload,
                        domoin:domoin,
                        departments:departments,
                        rank:rank
                    }
                });
            }
        };

        $('.demoTable .layui-btn').on('click', function (e) {
            e.preventDefault();
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });

//批量删除
        $("#deleteUserByIds").click(function () {
            var checkStatus = table.checkStatus('testReload'),
                data = checkStatus.data,
                file_id = "";
            if (data.length > 0) {
                for (var i in data) {
                    file_id += data[i].circular_id + ",";
                }
                console.log(file_id);
                layer.confirm('确定删除选中的数据？', {
                    icon: 3,
                    title: '提示信息'
                }, function (index) {
                    $.ajax({
                        url: '/delPolByIds',
                        dataType: 'json',
                        type: 'post',
                        data: {
                            ids: file_id
                        },
                        success: function (data) {
                            if (data.code == 0) {
                                layer.msg("删除成功", {
                                    icon: 6
                                }, function () {
                                    location.reload()
                                    // window.location.href = "/selUser"
                                });
                            } else {
                                layer.alert("删除失败")
                            }
                        }

                    })
                })
            } else {
                layer.msg("请选择需要删除的用户");
            }
        });



        table.on('toolbar(test)', function (obj) {
            var checkStatus = table.checkStatus(obj.config.id);
            switch (obj.event) {
                case 'getCheckLength':
                    var data = checkStatus.data;
                    layer.msg('选中了：' + data.length + ' 个');
                    break;
                case 'edit':
                    layer.msg(obj.data.rankName)
                    break;
                // case 'allat':
                //     layer.msg(obj.data.circularId)
                //     break;
                // case 'addlevel':
                //     layer.msg(obj.data.rankName)
                //     break;
                case 'del':
                    layer.msg(obj.data.circularId)
            }
            ;
        });
        //监听行工具事件
        table.on('tool(test)', function (obj) {
            var data = obj.data;

            if (obj.event === 'del') {
                var flag = confirm("您确定要删除吗？");
                if (flag) {
                    $.ajax({
                        type: "post",
                        dataType: "json",
                        url: 'delPolman',
                        data: {circularId: data.circular_id},
                        success: function (data) {
                            if (data == "200") {
                                alert("删除成功");
                                window.location.href = "/polmanjump";
                            } else {
                                alert("删除失败")
                            }
                        }
                    })
                }
                ;
            }


            if (obj.event === 'stop'){
                var flag = confirm("您确定要停用此政策？")
                if (flag){
                    $.ajax({
                        type: "post",
                        dataType: "json",
                        url: 'stopPolman',
                        data: {circularId: data.circular_id},
                        success: function (data) {
                            if (data == "200") {
                                alert("停用成功");
                                window.location.href = "/polmanjump";
                            } else {
                                alert("停用失败")
                            }
                        }
                    })
                }
            }




            if (obj.event === 'edit'){
                $("#boxDiv").css("display", "block");
                $("#circular_id").val(data.circular_id);
                $("#circular_title").val(data.circular_title);
                $("#circular_label").val(data.circular_label);
                $("#domoin_name").val(data.domoin_name);
                $("#department_name").val(data.department_name);
                $("#rank_name").val(data.rank_name);
                $("#project_name").val(data.project_name);
                $("#do_sel").val(data.domoin_name);
                $("#de_sel").val(data.department_name);
                $("#ra_sel").val(data.rank_name);
                $("#circular_content").val(data.circular_content);
                $("#ci_sel").val(data.project_name);

            }

        });
    });

</script>
<script>
    //日期范围
    layui.use('laydate', function () {
        var laydate = layui.laydate;
        laydate.render({
            elem: '#test6'
            //设置开始日期、日期日期的 input 选择器
            //数组格式为 2.6.6 开始新增，之前版本直接配置 true 或任意分割字符即可
            , range: ['#userCreateTime', '#userFinishTime']
            // ,range: true
        });
    });

    function addle(){
        $("#boxDiv2").css("display", "block");
    }
    //获取当前日期
    layui.use('laydate', function() {
        var laydate = layui.laydate;
        //常规用法
        laydate.render({
            type: 'date',
            value: new Date(new Date())
        });

    });


    var time=new Date();
    var date = time.getFullYear() + '-' + (time.getMonth() + 1) + '-' + time.getDate();
    console.log(date);


    function addsub() {
        var flag = confirm("您确定要添加该政策吗？")
        if (flag) {
            // let circular_id = document.getElementById("addcircular_id").value;
            let circular_title = document.getElementById("addcircular_title").value;
            let circular_label = document.getElementById("addcircular_label").value;
            let rank_name = document.getElementById("addra_sel").value;
            let time = date
            // let region_name = document.getElementById("addre_sel").value;
            let domoin_name = document.getElementById("adddo_sel").value;
            let department_name = document.getElementById("addde_sel").value;
            let circular_content = document.getElementById("addcircular_content").value;
            let project_name = document.getElementById("addci_sel").value;
            $.ajax({
                url: "addPolman",
                async: true,
                type: "post",
                data: {
                    // circularId: circular_id,
                    circularTitle: circular_title,
                    circularLabel: circular_label,
                    rankName: rank_name,
                    time: time,
                    // regionName: region_name,
                    domoinName: domoin_name,
                    departmentName:department_name,
                    circularContent: circular_content,
                    projectName: project_name
                },
                dataType: "json",
                success: function (data) {
                    if (data == "200") {
                        alert("添加成功")
                        window.location.href = "/polmanjump";
                        // window.open("/success.jsp")
                    } else if (data == "201") {
                        alert("添加失败，请重新修改")
                    }else {
                        alert("已有此政策")
                    }
                }
            })
        }
    }

    //修改
    function sub() {
        var flag = confirm("您确定要修改政策信息吗？")
        if (flag) {
            let circular_id = document.getElementById("circular_id").value;
            let circular_title = document.getElementById("circular_title").value;
            let circular_label = document.getElementById("circular_label").value;
            /*let time = */
            let rank_name = document.getElementById("ra_sel").value;
            // let region_name = document.getElementById("re_sel").value;
            let domoin_name = document.getElementById("do_sel").value;
            let department_name = document.getElementById("de_sel").value;
            let circular_content = document.getElementById("circular_content").value;
            let project_name = document.getElementById("ci_sel").value;
            $.ajax({
                url: "updPolman",
                async: true,
                type: "post",
                data: {
                    circularId: circular_id,
                    circularTitle: circular_title,
                    circularLabel: circular_label,
                    rankName: rank_name,

                    // regionName: region_name,
                    domoinName: domoin_name,
                    departmentName:department_name,
                    circularContent: circular_content,
                    projectName: project_name
                },
                dataType: "json",
                success: function (data) {
                    if (data == "200") {
                        alert("修改成功")
                        window.location.href = "/polmanjump";
                        // window.open("/success.jsp")
                    } else if (data == "201") {
                        alert("修改失败，请重新修改")
                    }else {
                        alert("已有此政策")
                    }
                }
            })
        }
    }

    //取消
    function cancel() {
        $("#boxDiv").css("display", "none");
        $("#boxDiv2").css("display", "none");
    }



</script>
<div style="width: 500px;background-color: whitesmoke; height: 500px; display: none;position: fixed;top:15%; left: 30%"
     id="boxDiv">
    <form onsubmit="return false">
        <table border="0" bgcolor="whitesmoke" cellspacing="0" align="center" width="500" height="400">
            <caption id="hear" style="font-size: 50px">修改政策</caption>
            <tr id="id" style="display: none">
                <th style="display: none">&nbsp;&nbsp;&nbsp;ID</th>
                <td colspan="5"><input class="layui-layer-input" type="hidden" id="circular_id" style="width: 93%" autocomplete="off"/></td>
            </tr>
            <tr>
                <th>标题</th>
                <td colspan="5"><input class="layui-layer-input" type="text" id="circular_title" style="width: 93%" autocomplete="off"/></td>
            </tr>
            <tr>
                <th>标签</th>
                <td colspan="5"><input class="layui-layer-input" type="text" id="circular_label" style="width: 93%" autocomplete="off"/></td>
            </tr>
            <tr>
<!--                <th>地区</th>-->
<!--                <td>-->
<!--                    <div class="layui-input-inline">-->
<!--                        <select id="re_sel" name="re_sel" lay-verify="required"  class="re_select" style="width: 170px"></select>-->
<!--                    </div>-->
<!--                </td>-->
                <th>领域</th>
                <td>
                    <div class="layui-input-inline">
                        <select id="do_sel" name="do_sel" lay-verify="required"  class="do_select" style="width: 170px" autocomplete="off"></select>
                    </div>
                </td>

                <th>部门</th>
                <td>
                    <div class="layui-input-inline">
                        <select id="de_sel" name="de_sel" lay-verify="required"  class="de_select" style="width: 170px" autocomplete="off"></select>
                    </div>
                </td>
            </tr>
            <tr>
                <th>级别</th>
                <td>
                    <div class="layui-input-inline">
                        <select id="ra_sel" name="ra_sel" lay-verify="required"  class="ra_select" style="width: 430%" autocomplete="off"></select>
                    </div>
                </td>
            </tr>
            <tr>
                <th>内容</th>
                <td colspan="5"><textarea cols="56" id="circular_content" autocomplete="off"></textarea></td>
            </tr>
            <tr>
                <th>包含项目</th>
                <td colspan="5">
                    <div class="layui-input-inline">
                        <select id="ci_sel" name="ci_sel" lay-verify="required"  class="ci_select" style="width: 170px" autocomplete="off"></select>
                    </div>
                </td>
            </tr>
            <tr>
                <td rowspan="2"  colspan="5" align="center">
                    <button class="button1" onclick="sub()">提交</button>
                    <button class="button2" onclick="cancel()">取消</button>
                </td>
            </tr>
        </table>
    </form>
</div>
<div style="width: 500px;background-color: whitesmoke; height: 500px; display: none;position: fixed;top:15%; left: 30%"
     id="boxDiv2">
    <form onsubmit="return false">
        <table border="0" bgcolor="whitesmoke" cellspacing="0" align="center" width="500" height="400">
            <caption  style="font-size: 50px">添加政策</caption>
            <!--            <tr id="addid">-->
            <!--                <th>&nbsp;&nbsp;&nbsp;ID</th>-->
            <!--                <td colspan="5"><input class="layui-layer-input" type="text" id="addcircular_id" style="width: 93%"/></td>-->
            <!--            </tr>-->
            <tr>
                <th>标题</th>
                <td colspan="5"><input class="layui-layer-input" type="text" id="addcircular_title" style="width: 93%" autocomplete="off"/></td>
            </tr>
            <tr>
                <th>标签</th>
                <td colspan="5"><input class="layui-layer-input" type="text" id="addcircular_label" style="width: 93%" autocomplete="off"/></td>
            </tr>
            <tr>
<!--                <th>地区</th>-->
<!--                <td>-->
<!--                    <div class="layui-input-inline">-->
<!--                        <select id="addre_sel" name="addre_sel" lay-verify="required"  class="re_select" style="width: 170px"></select>-->
<!--                    </div>-->
<!--                </td>-->
                <th>领域</th>
                <td>
                    <div class="layui-input-inline">
                        <select id="adddo_sel" name="adddo_sel" lay-verify="required"  class="do_select" style="width: 170px" autocomplete="off"></select>
                    </div>
                </td>

                <th>部门</th>
                <td>
                    <div class="layui-input-inline">
                        <select id="addde_sel" name="addde_sel" lay-verify="required"  class="de_select" style="width: 170px" autocomplete="off"></select>
                    </div>
                </td>
            </tr>
            <tr>
                <th>级别</th>
                <td>
                    <div class="layui-input-inline">
                        <select id="addra_sel" name="addra_sel" lay-verify="required"  class="ra_select" style="width: 430%" autocomplete="off"></select>
                    </div>
                </td>
            </tr>
            <tr>
                <th>内容</th>
                <td colspan="5"><textarea cols="56" id="addcircular_content" autocomplete="off"></textarea></td>
            </tr>
            <tr>
                <th>包含项目</th>
                <td colspan="5">
                    <div class="layui-input-inline">
                        <select id="addci_sel" name="addci_sel" lay-verify="required"  class="ci_select" style="width: 170px" autocomplete="off"></select>
                    </div>
                </td>
            </tr>
            <tr>
                <td rowspan="2"  colspan="5" align="center">
                    <button class="button1" onclick="addsub()">提交</button>
                    <button class="button2" onclick="cancel()">取消</button>
                </td>
            </tr>
        </table>
    </form>
</div>

<script>

    layui.use('form',function(){
        var $ = layui.jquery
        var form = layui.form
//地区
//         $.ajax({
//             url: '/selRe',
//             dataType: 'json',
//             type: 'post',
//             success: function(data) {
//                 if (data!== null) {
//                     $("#addre_sel").empty();
//                     $("#addre_sel").append(new Option("请选择地区", "0"));
//                     $.each(data, function(index, item) {
//                         var domo = item.regionName
//                         $('#addre_sel').append(new Option(JSON.stringify(domo).replace(/\"/g, "")));
//                     });
//                 } else {
//                     $("#addre_sel").append(new Option("暂无数据", ""));
//                 }
//                 //重新渲染
//                 form.render("addre_select");
//             }
//         });
//领域
        $.ajax({
            url: '/selDo',
            dataType: 'json',
            type: 'post',
            success: function(data) {
                if (data!== null) {
                    $("#adddo_sel").empty();
                    $("#adddo_sel").append(new Option("请选择领域", "0"));
                    $.each(data, function(index, item) {
                        var domo = item.domoinName
                        $('#adddo_sel').append(new Option(JSON.stringify(domo).replace(/\"/g, "")));
                    });
                } else {
                    $("#adddo_sel").append(new Option("暂无数据", ""));
                }
                //重新渲染
                form.render("adddo_select");
            }
        });
//部门
        $.ajax({
            url: '/selDe',
            dataType: 'json',
            type: 'post',
            success: function(data) {
                if (data!== null) {
                    $("#addde_sel").empty();
                    $("#addde_sel").append(new Option("请选择部门", "0"));
                    $.each(data, function(index, item) {
                        var domo = item.departmentName
                        $('#addde_sel').append(new Option(JSON.stringify(domo).replace(/\"/g, "")));
                    });
                } else {
                    $("#addde_sel").append(new Option("暂无数据", ""));
                }
                //重新渲染
                form.render("addde_select");
            }
        });
//级别
        $.ajax({
            url: '/selRa',
            dataType: 'json',
            type: 'post',
            success: function(data) {
                if (data!== null) {
                    $("#addra_sel").empty();
                    $("#addra_sel").append(new Option("请选择级别", "0"));
                    $.each(data, function(index, item) {
                        var domo = item.rankName
                        $('#addra_sel').append(new Option(JSON.stringify(domo).replace(/\"/g, "")));
                    });
                } else {
                    $("#addra_sel").append(new Option("暂无数据", ""));
                }
                //重新渲染
                form.render("addra_select");
            }
        });

// 项目
        $.ajax({
            url: '/selCi',
            dataType: 'json',
            type: 'post',
            success: function(data) {
                if (data!== null) {
                    $("#addci_sel").empty();
                    $("#addci_sel").append(new Option("请选择项目", "0"));
                    $.each(data, function(index, item) {
                        var domo = item.projectName
                        $('#addci_sel').append(new Option(JSON.stringify(domo).replace(/\"/g, "")));
                    });
                } else {
                    $("#addci_sel").append(new Option("暂无数据", ""));
                }
                //重新渲染
                form.render("addci_select");
            }
        });
        // });



//修改地区
        $.ajax({
            url: '/selRe',
            dataType: 'json',
            type: 'post',
            success: function(data) {
                if (data!== null) {
                    $("#re_sel").empty();
                    $("#re_sel").append(new Option("请选择地区", "0"));
                    $.each(data, function(index, item) {
                        var domo = item.regionName
                        $('#re_sel').append(new Option(JSON.stringify(domo).replace(/\"/g, "")));
                    });
                } else {
                    $("#re_sel").append(new Option("暂无数据", ""));
                }
                //重新渲染
                form.render("re_select");
            }
        });
//修改领域
        $.ajax({
            url: '/selDo',
            dataType: 'json',
            type: 'post',
            success: function(data) {
                if (data!== null) {
                    $("#do_sel").empty();
                    $("#do_sel").append(new Option("请选择领域", "0"));
                    $.each(data, function(index, item) {
                        var domo = item.domoinName
                        $('#do_sel').append(new Option(JSON.stringify(domo).replace(/\"/g, "")));
                    });
                } else {
                    $("#do_sel").append(new Option("暂无数据", ""));
                }
                //重新渲染
                form.render("do_select");
            }
        });
//修改部门
        $.ajax({
            url: '/selDe',
            dataType: 'json',
            type: 'post',
            success: function(data) {
                if (data!== null) {
                    $("#de_sel").empty();
                    $("#de_sel").append(new Option("请选择部门", "0"));
                    $.each(data, function(index, item) {
                        var domo = item.departmentName
                        $('#de_sel').append(new Option(JSON.stringify(domo).replace(/\"/g, "")));
                    });
                } else {
                    $("#de_sel").append(new Option("暂无数据", ""));
                }
                //重新渲染
                form.render("de_select");
            }
        });
        //级别
        $.ajax({
            url: '/selRa',
            dataType: 'json',
            type: 'post',
            success: function(data) {
                if (data!== null) {
                    $("#ra_sel").empty();
                    $("#ra_sel").append(new Option("请选择级别", "0"));
                    $.each(data, function(index, item) {
                        var domo = item.rankName
                        $('#ra_sel').append(new Option(JSON.stringify(domo).replace(/\"/g, "")));
                    });
                } else {
                    $("#ra_sel").append(new Option("暂无数据", ""));
                }
                //重新渲染
                form.render("ra_select");
            }
        });

// 修改项目
        $.ajax({
            url: '/selCi',
            dataType: 'json',
            type: 'post',
            success: function(data) {
                if (data!== null) {
                    $("#ci_sel").empty();
                    $("#ci_sel").append(new Option("请选择项目", "0"));
                    $.each(data, function(index, item) {
                        var domo = item.projectName
                        $('#ci_sel').append(new Option(JSON.stringify(domo).replace(/\"/g, "")));
                    });
                } else {
                    $("#ci_sel").append(new Option("暂无数据", ""));
                }
                //重新渲染
                form.render("ci_select");
            }
        });




    //搜索部门
    layui.use('form', function () {
        var $ = layui.jquery;
        var form = layui.form;
        //地区
        $.ajax({
            url: '/selDe',
            dataType: 'json',
            type: 'post',
            success: function(data) {
                if (data!== null) {
                    $("#departments").empty();
                    $("#departments").append(new Option("请选择部门", ""));
                    $.each(data, function(index, item) {
                        var domo = item.departmentName
                        $('#departments').append(new Option(JSON.stringify(domo).replace(/\"/g, "")));
                    });
                } else {
                    $("#departments").append(new Option("暂无数据", ""));
                }
                //重新渲染
                form.render("#departments");
            }
        });

//搜索领域
        $.ajax({
            url: '/selDo',
            dataType: 'json',
            type: 'post',
            success: function(data) {
                if (data!== null) {
                    $("#domoin").empty();
                    $("#domoin").append(new Option("请选择领域", ""));
                    $.each(data, function(index, item) {
                        var domo = item.domoinName
                        $('#domoin').append(new Option(JSON.stringify(domo).replace(/\"/g, "")));
                    });
                } else {
                    $("#domoin").append(new Option("暂无数据", ""));
                }
                //重新渲染
                form.render("domoin");
            }
        });
    })

    //搜索级别
    $.ajax({
        url: '/selRa',
        dataType: 'json',
        type: 'post',
        success: function(data) {
            if (data!== null) {
                $("#rank").empty();
                $("#rank").append(new Option("请选择级别", ""));
                $.each(data, function(index, item) {
                    var domo = item.rankName
                    $('#rank').append(new Option(JSON.stringify(domo).replace(/\"/g, "")));
                });
            } else {
                $("#rank").append(new Option("暂无数据", ""));
            }
            //重新渲染
            form.render("rank");
        }
    });
    });
</script>
</body>
</html>
